// Tutorial.cs
//

using System;
using System.Collections.Generic;
using jQueryApi;
using System.Html;

namespace TuringMachine
{
    public class Tutorial
    {
        MessageBoxWithImage m_page;
        jQueryObject m_parent;
        public event EventHandler DialogClosed;
        public int m_iCurrentPage = 0;

        public Tutorial(jQueryObject parent)
        {
            m_parent = parent;
            m_page = new MessageBoxWithImage(m_parent);
            m_page.OnClose += new DialogEventHandler(m_page_OnClose);
            ShowPage();
        }

        private void ShowPage()
        {

            FillPage();
            m_page.Show();
        }

        void m_page_OnClose(MessageBoxBase dlg, bool bOkPressed)
        {
            if (bOkPressed)
            {
                m_iCurrentPage--;
                if (m_iCurrentPage < 0)
                {
                    if (DialogClosed != null)
                        DialogClosed(this, null);
                }
                else
                {
                    ShowPage();
                }
            }
            else
            {
                m_iCurrentPage++;
                if (m_iCurrentPage > 7)
                {
                    if (DialogClosed != null)
                        DialogClosed(this, null);
                }
                else
                {
                    ShowPage();
                }
            }
        }

        private void FillPage()
        {
            m_page.pOkText = "Previous";
            m_page.pCancelText = "Next";

            switch (m_iCurrentPage)
            {
                case 0:
                    m_page.pTitleText = "Welcome to the tutorial";
                    m_page.pText = "This game consists of resolving computational problems using a simplified version of a Turing Machine. " +
                       "The machine begins executing at the top left corner of the board and ends when it reaches a confirmation status or an empty cell.<br /><br />" +
                       "Press &laquo;Next&raquo; to learn about the different components in the game";
                    m_page.pImage = "http://edu.selfip.net/images/TM/all.png";
                    m_page.pOkText = "Leave";
                    m_page.SetLayout(1);
                    break;
                case 1:
                    m_page.pTitleText = "The board";
                    m_page.pText = "This is the board. The board is composed of cells. You can configure a cell to make an operation or you can configure it to just move the cursor. <br />  " +
                       "When the machine reaches an unconfigured cell it stops. ";
                    m_page.pImage = "http://edu.selfip.net/images/TM/cells.png";
                    m_page.SetLayout(0);
                    break;
                case 2:
                    m_page.pTitleText = "The tape";
                    m_page.pText = "Under the board is the tape. This is an essential part of the machine since the target of the challenges is either modify the data in the tape or " +
                        "recognize whether the data has specific properties and stop the machine with an acceptance status.<br/><br/>" +
                        "Although you begin with just one tape you can upgrade to two tapes if you collect enough credits.";
                    m_page.pImage = "http://edu.selfip.net/images/TM/tape.png";
                    m_page.SetLayout(2);
                    break;
                case 3:
                    m_page.pTitleText = "The operations";
                    m_page.pText = "To change the operation of any cell just click on it. When this window appears you can modify how the machine behaves when the execution pointer reaches the selected cell.<br/><br/>" +
                        "Depending on how you upgrade your machine, you will see different operations. During the game a small description of the operation appears when you hover the mouse pointer over each of the operation icons";
                    m_page.pImage = "http://edu.selfip.net/images/TM/editing.png";
                    m_page.SetLayout(0);
                    break;
                case 4:
                    m_page.pTitleText = "The operations (II)";
                    m_page.pText = "On the central part of the window you can set where the execution point moves when the operation completes.<br/><br/>"+
                        "After getting the double movement upgrade, you can set a jump over adjacent cells by clicking twice on the movement cell";
                    m_page.pImage = "http://edu.selfip.net/images/TM/editing.png";
                    m_page.SetLayout(1);
                    break;
                case 5:
                    m_page.pTitleText = "Conditional operations";
                    m_page.pText = "Some operations move the pointer to a different location depending on the result of a comparison. For these operations there is a right movement panel, where you can choose " +
                        "the target cell, when the compared values are equal.<br/><br/>" +
                        "Compare and write operations need also an extra value, so the machine knows what to compare to or what to write to the tape. This value is set with the inferior line of icons";
                    m_page.pImage = "http://edu.selfip.net/images/TM/editing_mov.png";
                    m_page.SetLayout(0);
                    break;
                case 6:
                    m_page.pTitleText = "Level operations";
                    m_page.pText = "Once you are ready to deliver your machine press the &laquo;Test&raquo; button. The machine will be tested and you will be given some credits if it passes all the tests. With the buttons "+
                        "&laquo;Save&raquo; and &laquo;Load&raquo; you can share the machine with other users or reuse your structures in other levels. Some upgrades will add new buttons such as selection or debugging";
                    m_page.pImage = "http://edu.selfip.net/images/TM/buttons.png";
                    m_page.SetLayout(1);
                    break;
                case 7:
                    m_page.pTitleText = "Have fun!";
                    m_page.pText = "All your progress is stored in the browser web store, so you can quit and come later again and continue the game. If you messed up a level and don't want to overwrite a previous design just press F5.<br/><br/>"+
                        "This concludes the tutorial, if you have any questions you can post them in the <a href='http://edu.selfip.net/forum/'>forum</a>";
                    m_page.pImage = "http://edu.selfip.net/images/TM/all.png";
                    m_page.SetLayout(2);
                    break;
            }
        }

    }
}
